Usage Analysis of JavaScript Associative Array [Concept Definition Traversal]

  • 2021-08-03 09:16:23
  • OfStack

This article illustrates the use of JavaScript associative arrays. Share it for your reference, as follows:

Basic concepts:

An "associative array" is an array with a special index. It can be indexed not only by integers, but also by strings or other types of values (except NULL). The index values of associative arrays are arbitrary scalars, called Keys, which can be used later to retrieve the values in the array. The elements of associative arrays have no specific order.

What does the associative array look like?

var defs = [W3C: "World Wide Web Consortium", DOM: "Document Object Model"];

How do I define associative arrays?


var defs = [];
defs[key] = value;

Note: key and value need to be assigned different values.

How do I iterate through associative arrays?


for (key in defs) {
  //  Variable  key  It can be used directly. 
  var value = defs[key]; // Each key For the value of. 
}

For more readers interested in JavaScript related content, please check the topics on this site: "Summary of JavaScript Array Operation Skills", "Summary of JavaScript Sorting Algorithm", "Summary of JavaScript Mathematical Operation Usage", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript Traversal Algorithm and Skills", "Summary of JavaScript Search Algorithm Skills" and "Summary of JavaScript Error and Debugging Skills"

I hope this article is helpful to everyone's JavaScript programming.


Related articles: